<?php
session_start();
include("load-settings.php");

if(!isset($_SESSION['user']))
	header("Location: login.php");

$user = mysql_real_escape_string($_SESSION['user']);
$result = mysql_query("SELECT * FROM user WHERE id = $user");
$row = mysql_fetch_array($result);

if($row['type'] != 2 && $row['type'] != 3)
	header("Location: home.php");
?>
<!doctype html>
<html>
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, maximum-scale=1, initial-scale=1, user-scalable=0">
    <link rel="icon" href="http://www.veteranboosters.com/wp-content/uploads/2014/04/favicon4.png" type="image/x-icon"/>
    <link rel="shortcut icon" href="http://www.veteranboosters.com/wp-content/uploads/2014/04/favicon4.png" type="image/x-icon"/>
  <!-- Always force latest IE rendering engine or request Chrome Frame -->
  <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">

  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:400,600,800">

  <!-- Use title if it's in the page YAML frontmatter -->
  <title>Veteran Boosters Order Tracking</title>


  <!--[if lt IE 9]>
  <script src="../../javascripts/vendor/html5shiv.js" type="text/javascript"></script>
  <script src="../../javascripts/vendor/excanvas.js" type="text/javascript"></script>
  <![endif]-->
<link rel="stylesheet" href="css/bootstrap.min.css" />
<link rel="stylesheet" href="css/font-awesome.css" />
<link rel="stylesheet" href="css/fullcalendar.css" />
<link rel="stylesheet" href="css/jquery.jscrollpane.css" />	
<link rel="stylesheet" href="css/unicorn.css" />
  <link href="stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />
  <script src="javascripts/application.js" type="text/javascript"></script>
</head>

<?php
	include("top.php");
?>

  <div class="container-fluid padded">
    <div class="row-fluid">

      <!-- Breadcrumb line -->

			<div id="breadcrumb" >
				<a href="/" title="" class="tip-bottom" data-original-title="Go to Home"><i class="fa fa-home"></i> Home</a>
				<a href="#">Members</a>
				<a href="#" class="current">Completed orders     </a>
				</div>
			</div>
  </div>

  <div class="container-fluid padded">
  <div class="row-fluid">
   <div class="span12">
      <div class="box">
         <div class="box-header">
            <span class="title">Boosting Orders</span> <span class = "title">Records per page:</span><select onchange = "change_boost_count()" id = "boost_page_count" style = "line-height: 1; margin-top: 5px; margin-bottom: 0px;"><option>20</option><option>100</option><option>500</option></select>
         </div>
         <div class="box-content">
            <table class="table table-normal">
               <thead>
                  <tr>
					 <td>Order ID</td>
                     <td>Booster</td>
					 <td>Summoner</td>
                     <td>Region</td>
                     <td>Booster paypal</td>
					 <td>Total paid (booster)</td>
					 <td>Customer paypal</td>
					 <td>Total paid (customer)</td>
					 <td>Details</td>
                  </tr>
               </thead>
               <tbody id = "complete_boost_records">
			   <?php
					$result = mysql_query("SELECT * FROM order_record WHERE verified_complete = 1") or die(mysql_error());

					$total = mysql_num_rows($result);

					//$result = mysql_query("SELECT order_record.*, booster_order.*, order_record.id AS order_id FROM order_record, booster_order WHERE order_record.verified_complete = 1 AND order_record.id = booster_order.order_record ORDER BY order_record.timestamp DESC LIMIT 20") or die(mysql_error());

					$result = mysql_query("SELECT * FROM order_record WHERE verified_complete = 1 ORDER BY timestamp DESC LIMIT 20");

					while($row = mysql_fetch_array($result))
					{
						$subresult = mysql_query("SELECT * FROM booster_order WHERE order_record = ".$row['id']." ORDER BY timestamp DESC LIMIT 1") or die(mysql_error());
						$subrow = mysql_fetch_array($subresult);

						if(mysql_num_rows($subresult) == 0)
						{
							$booster_row['username'] = "No booster";
						}
						else
						{
							$booster_result = mysql_query("SELECT * FROM user WHERE id = ".$subrow['booster']) or die(mysql_error());
							$booster_row = mysql_fetch_array($booster_result);
						}

						$user_result = mysql_query("SELECT * FROM user WHERE id = ".$row['user']) or die(mysql_error());
						$user_row = mysql_fetch_array($user_result);

						echo "<tr><td>".$row['id']."</td>";
						echo "<td>".$booster_row['username']."</td>";
						echo "<td>".$row['summoner']."</td>";
						echo "<td>".strtoupper($row['region'])."</td>";
						echo "<td>".$booster_row['paypal']."</td>";
						echo "<td>".$row['booster_payout']."</td>";
						echo "<td>".$user_row['paypal']."</td>";
						echo "<td>".$row['payout']."</td>";
						echo "<td><a href='order.php?id=".$row['id']."' class='btn btn-success btn-xs'>Details</a></td>";
						echo "</tr>";
					}
					?>
					
					
			   </tbody>
            </table>
							
										
									

					<?php

					if($total > 20)
					{
						echo '<div class="pagination pagination-centered pagination-small">
								<div id="page-selection" class="pagination">
									<ul class="bootpag">';
						$pages = ceil($total/20);

						$x = 1;

						while($x <= $pages)
						{
							echo "<li><a href='#' onclick = 'complete_boost_page(".$x.")'>".$x."</a></li>";
							$x++;
						}

						echo '</ul>
						</div>
					</div>';
					}
					
				?>
				
         </div>
      </div>
   </div>
</div>
<!--<div class="row-fluid">
   <div class="span12">
      <div class="box">
         <div class="box-header">
            <span class="title">Duo Queue Orders</span> <span class = "title">Records per page:</span><select onchange = "change_duo_count()" id = "duo_page_count" style = "line-height: 1; margin-top: 5px; margin-bottom: 0px;"><option>20</option><option>100</option><option>500</option></select>
         </div>
         <div class="box-content">
            <table class="table table-normal">
               <thead>
                  <tr>
					 <td>Order ID</td>
                     <td>Booster</td>
					 <td>Summoner</td>
                     <td>Region</td>
                     <td>Booster paypal</td>
					 <td>Total paid (booster)</td>
					 <td>Customer paypal</td>
					 <td>Total paid (customer)</td>
					 <td>Details</td>
                  </tr>
               </thead>
               <tbody id = "complete_duo_records">
			   <?php
					$result = mysql_query("SELECT * FROM duo_order WHERE verified_complete = 1") or die(mysql_error());

					$total = mysql_num_rows($result);

					$result = mysql_query("SELECT * FROM duo_order WHERE verified_complete = 1 ORDER BY timestamp DESC LIMIT 20") or die(mysql_error());

					while($row = mysql_fetch_array($result))
					{
						$subresult = mysql_query("SELECT * FROM booster_duo WHERE duo_order = ".$row['id']." ORDER BY timestamp DESC LIMIT 1") or die(mysql_error());
						$subrow = mysql_fetch_array($subresult);

						if(mysql_num_rows($subresult) == 0)
						{
							$booster_row['username'] = "No booster";
						}
						else
						{
							$booster_result = mysql_query("SELECT * FROM user WHERE id = ".$subrow['booster']) or die(mysql_error());
							$booster_row = mysql_fetch_array($booster_result);
						}

						$user_result = mysql_query("SELECT * FROM user WHERE id = ".$row['user']);
						$user_row = mysql_fetch_array($user_result);

						echo "<tr><td>".$row['id']."</td>";
						echo "<td>".$booster_row['username']."</td>";
						echo "<td>".$row['summoner']."</td>";
						echo "<td>".strtoupper($row['region'])."</td>";
						echo "<td>".$booster_row['paypal']."</td>";
						echo "<td>".$row['booster_payout']."</td>";
						echo "<td>".$user_row['paypal']."</td>";
						echo "<td>".$row['payout']."</td>";
						echo "<td><a href='duo_order.php?id=".$row['id']."' class='btn btn-success btn-xs'>Details</a></td>";
						echo "</tr>";
					}
					
				?>
			   </tbody>
            </table>

			<?php

					if($total > 20)
					{
						echo '<div class="pagination pagination-centered pagination-small">
								<div id="page-selection" class="pagination">
									<ul class="bootpag">';
						$pages = ceil($total/20);

						$x = 1;

						while($x <= $pages)
						{
							echo "<li><a href='#' onclick = 'complete_duo_page(".$x.")'>".$x."</a></li>";
							$x++;
						}

						echo '</ul>
						</div>
					</div>';
					}
					
				?>
         </div>
      </div>
   </div>
</div>-->
  <!--
<div class="row-fluid">
   <div class="span12">
      <div class="box">
         <div class="box-header">
            <span class="title">Leveling Orders</span> <span class = "title">Records per page:</span><select onchange = "change_leveling_count()" id = "leveling_page_count" style = "line-height: 1; margin-top: 5px; margin-bottom: 0px;"><option>20</option><option>100</option><option>500</option></select>
         </div>
         <div class="box-content">
            <table class="table table-normal">
               <thead>
                  <tr>
					 <td>Order ID</td>
					 <td>Purchase Date</td>
					 <td>Customer paypal</td>
					 <td>Levels</td>
					 <td>Start level</td>
					 <td>Payment</td>
					 <td>Details</td>
                  </tr>
               </thead>
               <tbody id = "complete_leveling_records">
			   <?php
					$result = mysql_query("SELECT * FROM leveling_order WHERE complete = 1") or die(mysql_error());

					$total = mysql_num_rows($result);

					$result = mysql_query("SELECT * FROM leveling_order WHERE complete = 1 ORDER BY timestamp DESC LIMIT 20") or die(mysql_error());

					while($row = mysql_fetch_array($result))
					{
						$user_result = mysql_query("SELECT * FROM user WHERE id = ".$row['user']);
						$user_row = mysql_fetch_array($user_result);

						echo "<tr><td>".$row['id']."</td>";
						echo "<td>".date("d M Y", $row['timestamp'])."</td>";
						echo "<td>".$user_row['paypal']."</td>";
						echo "<td>".$row['levels']."</td>";
						echo "<td>".$row['start_level']."</td>";
						echo "<td>".$row['payout']."</td>";
						echo "<td><a href='leveling_order.php?id=".$row['id']."' class='btn btn-success btn-xs'>Details</a></td>";
						echo "</tr>";
					}
					
				?>
			   </tbody>
            </table>
			<?php

					if($total > 20)
					{
						echo '<div class="pagination pagination-centered pagination-small">
								<div id="page-selection" class="pagination">
									<ul class="bootpag">';
						$pages = ceil($total/20);

						$x = 1;

						while($x <= $pages)
						{
							echo "<li><a href='#' onclick = 'complete_leveling_page(".$x.")'>".$x."</a></li>";
							$x++;
						}

						echo '</ul>
						</div>
					</div>';
					}
					
				?>
         </div>
      </div>
   </div>
</div> -->
  <!--
<div class="row-fluid">
   <div class="span12">
      <div class="box">
         <div class="box-header">
            <span class="title">Referral Orders</span> <span class = "title">Records per page:</span><select onchange = "change_referral_count()" id = "referral_page_count" style = "line-height: 1; margin-top: 5px; margin-bottom: 0px;"><option>20</option><option>100</option><option>500</option></select>
         </div>
         <div class="box-content">
            <table class="table table-normal">
               <thead>
                  <tr>
					 <td>Order ID</td>
					 <td>Purchase Date</td>
					 <td>Customer paypal</td>
					 <td>Referrals</td>
					 <td>Link</td>
					 <td>Payment</td>
					 <td>Details</td>
                  </tr>
               </thead>
               <tbody id = "complete_referral_records">
			   <?php
					$subresult = mysql_query("SELECT * FROM option_list WHERE name = 'Price per 25 referrals'");
					$subrow = mysql_fetch_array($subresult);
					$price = $subrow['value'];

					$result = mysql_query("SELECT * FROM referral_order WHERE complete = 1") or die(mysql_error());

					$total = mysql_num_rows($result);

					$result = mysql_query("SELECT * FROM referral_order WHERE complete = 1 ORDER BY timestamp DESC LIMIT 20") or die(mysql_error());

					while($row = mysql_fetch_array($result))
					{
						$user_result = mysql_query("SELECT * FROM user WHERE id = ".$row['user']);
						$user_row = mysql_fetch_array($user_result);

						echo "<tr><td>".$row['id']."</td>";
						echo "<td>".date("d M Y", $row['timestamp'])."</td>";
						echo "<td>".$user_row['paypal']."</td>";
						echo "<td>".$row['referrals']."</td>";
						echo "<td>".$row['link']."</td>";
						echo "<td>".($row['referrals'] * ($price/25))."</td>";
						echo "<td><a href='referral_order.php?id=".$row['id']."' class='btn btn-success btn-xs'>Details</a></td>";
						echo "</tr>";
					}
					
				?>
			   </tbody>
            </table>
			<?php

					if($total > 20)
					{
						echo '<div class="pagination pagination-centered pagination-small">
								<div id="page-selection" class="pagination">
									<ul class="bootpag">';
						$pages = ceil($total/20);

						$x = 1;

						while($x <= $pages)
						{
							echo "<li><a href='#' onclick = 'complete_referral_page(".$x.")'>".$x."</a></li>";
							$x++;
						}

						echo '</ul>
						</div>
					</div>';
					}
					
				?>
         </div>
      </div>
   </div>
</div>     -->
  <!--
<div class="row-fluid">
   <div class="span12">
      <div class="box">
         <div class="box-header">
            <span class="title">Account Orders</span> <span class = "title">Records per page:</span><select onchange = "change_account_count()" id = "account_page_count" style = "line-height: 1; margin-top: 5px; margin-bottom: 0px;"><option>20</option><option>100</option><option>500</option></select>
         </div>
         <div class="box-content">
            <table class="table table-normal">
               <thead>
                  <tr>
					 <td>Order ID</td>
					 <td>Purchase Date</td>
					 <td>Customer paypal</td>
					 <td>Login</td>
					 <td>Password</td>
					 <td>Region</td>
					 <td>Payment</td>
                  </tr>
               </thead>
               <tbody id = "complete_account_records">
			   <?php
					$result = mysql_query("SELECT * FROM account_order") or die(mysql_error());

					$total = mysql_num_rows($result);

					$result = mysql_query("SELECT * FROM account_order ORDER BY timestamp DESC LIMIT 20") or die(mysql_error());

					while($row = mysql_fetch_array($result))
					{
						$user_result = mysql_query("SELECT * FROM user WHERE id = ".$row['user']);
						$user_row = mysql_fetch_array($user_result);

						$account_result = mysql_query("SELECT * FROM bulk_account WHERE order_id = ".$row['id']);
						$account_row = mysql_fetch_array($account_result);

						if($account_row['referrals'] == 0)
						{
							$subresult = mysql_query("SELECT * FROM option_list WHERE name = 'Level 30 Account price'");
							$subrow = mysql_fetch_array($subresult);
							$price = $subrow['value'];
						}
						else if($account_row['referrals'] == 50)
						{
							$subresult = mysql_query("SELECT * FROM option_list WHERE name = '50 Referral account price'");
							$subrow = mysql_fetch_array($subresult);
							$price = $subrow['value'];
						}
						else if($account_row['referrals'] == 100)
						{
							$subresult = mysql_query("SELECT * FROM option_list WHERE name = '100 Referral account price'");
							$subrow = mysql_fetch_array($subresult);
							$price = $subrow['value'];
						}

						echo "<tr><td>".$row['id']."</td>";
						echo "<td>".date("d M Y", $row['timestamp'])."</td>";
						echo "<td>".$user_row['paypal']."</td>";
						echo "<td>".$account_row['username']."</td>";
						echo "<td>".$account_row['password']."</td>";
						echo "<td>".$account_row['region']."</td>";
						echo "<td>".$price."</td>";
						echo "</tr>";
					}
					
				?>
			   </tbody>
            </table>
			<?php

					if($total > 20)
					{
						echo '<div class="pagination pagination-centered pagination-small">
								<div id="page-selection" class="pagination">
									<ul class="bootpag">';
						$pages = ceil($total/20);

						$x = 1;

						while($x <= $pages)
						{
							echo "<li><a href='#' onclick = 'complete_account_page(".$x.")'>".$x."</a></li>";
							$x++;
						}

						echo '</ul>
						</div>
					</div>';
					}
					
				?>
         </div>
      </div>
   </div>
</div>       -->
</div>
<script>
var boost_per_page = 20;
var duo_per_page = 20;
var leveling_per_page = 20;
var referral_per_page = 20;
var account_per_page = 20;

function change_boost_count ()
{
	boost_per_page = document.getElementById("boost_page_count").value;

	complete_boost_page(1);
}
function complete_boost_page (page)
{
	var ajaxHandler = new XMLHttpRequest();

	ajaxHandler.onreadystatechange = function ()
	{
		if(ajaxHandler.readyState == 4)
		{
			document.getElementById("complete_boost_records").innerHTML = ajaxHandler.responseText;
		}
	}

	var form = new FormData();
	form.append("per_page", boost_per_page);
	form.append("page", page);

	ajaxHandler.open("POST", "complete_boost_page.php", true);
	ajaxHandler.send(form);
}

function change_duo_count ()
{
	duo_per_page = document.getElementById("duo_page_count").value;

	complete_duo_page(1);
}
function complete_duo_page (page)
{
	var ajaxHandler = new XMLHttpRequest();

	ajaxHandler.onreadystatechange = function ()
	{
		if(ajaxHandler.readyState == 4)
		{
			document.getElementById("complete_duo_records").innerHTML = ajaxHandler.responseText;
		}
	}

	var form = new FormData();
	form.append("per_page", duo_per_page);
	form.append("page", page);

	ajaxHandler.open("POST", "complete_duo_page.php", true);
	ajaxHandler.send(form);
}

function change_leveling_count ()
{
	leveling_per_page = document.getElementById("leveling_page_count").value;

	complete_leveling_page(1);
}
function complete_leveling_page (page)
{
	var ajaxHandler = new XMLHttpRequest();

	ajaxHandler.onreadystatechange = function ()
	{
		if(ajaxHandler.readyState == 4)
		{
			document.getElementById("complete_leveling_records").innerHTML = ajaxHandler.responseText;
		}
	}

	var form = new FormData();
	form.append("per_page", leveling_per_page);
	form.append("page", page);

	ajaxHandler.open("POST", "complete_leveling_page.php", true);
	ajaxHandler.send(form);
}

function change_referral_count ()
{
	referral_per_page = document.getElementById("referral_page_count").value;

	complete_referral_page(1);
}
function complete_referral_page (page)
{
	var ajaxHandler = new XMLHttpRequest();

	ajaxHandler.onreadystatechange = function ()
	{
		if(ajaxHandler.readyState == 4)
		{
			document.getElementById("complete_referral_records").innerHTML = ajaxHandler.responseText;
		}
	}

	var form = new FormData();
	form.append("per_page", referral_per_page);
	form.append("page", page);

	ajaxHandler.open("POST", "complete_referral_page.php", true);
	ajaxHandler.send(form);
}
function change_account_count ()
{
	account_per_page = document.getElementById("account_page_count").value;

	complete_account_page(1);
}
function complete_account_page (page)
{
	var ajaxHandler = new XMLHttpRequest();

	ajaxHandler.onreadystatechange = function ()
	{
		if(ajaxHandler.readyState == 4)
		{
			document.getElementById("complete_account_records").innerHTML = ajaxHandler.responseText;
		}
	}

	var form = new FormData();
	form.append("per_page", account_per_page);
	form.append("page", page);

	ajaxHandler.open("POST", "complete_account_page.php", true);
	ajaxHandler.send(form);
}
</script>
    </div>
<?php
	include("bottom.php");
?>